package com.guchenbo.bigdata.spark;

import com.clearspring.analytics.util.Lists;
import com.google.common.collect.Maps;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author guchenbo
 */
public class EsDemo2 {

    public static void main(String[] args) throws ParseException {
        System.out.println(UUID.randomUUID().toString().replaceAll("-", ""));

        //        EsDemo.saveMap(map);
    }

    public static List<Map<String, Object>> buildList() throws Exception {
        String str = "20201101";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Date start = sdf.parse(str);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(start);
        List<Date> list = new ArrayList<>();
        for (int i = 0; i < 7; i++) {
            calendar.add(Calendar.DAY_OF_YEAR, 1);
            list.add(calendar.getTime());
        }

        Map<String, List<Map<String, Object>>> map = Maps.newHashMap();
        List<Map<String, Object>> logs = Lists.newArrayList();
        for (int i = 0; i < 100; i++) {
            Map<String, Object> log = Maps.newHashMap();
            log.put("modelUuid", UUID.randomUUID().toString().replaceAll("-", ""));
            log.put("modelVersion", "V1.0.0");
            Date d = list.get(new Random().nextInt(list.size()));

            log.put("timestamp", d.getTime());
            String key = sdf.format(d);

            log.put("bizDate", key);

            List<Map<String, Object>> ll = map.get(key);
            if (ll == null) {
                ll = Lists.newArrayList();
                map.put(key, ll);
            }
            ll.add(log);
            logs.add(log);
        }
        return logs;
    }
}
